package jni;

/**
 * @author fengbo
 * @version 1.0.0
 * @date 2019/2/17 14:47
 * @since JDK 1.8
 */
public class MyJNI {

    public static native int add(int a, int b);

    static {
        System.load(MyJNI.class.getResource("/").getPath() + "jni_MyJNI.so");
    }

    /**
     * 1. javac jni/MyJNI.java
     * 2. javah jni.MyJNI
     * 3. vim jni_MyJNI.c
            #include "jni_MyJNI.h"

            jint Java_jni_MyJNI_add(JNIEnv* env, jclass obj, jint a, jint b) {
                return a + b;
            }
     * 4. gcc -I/usr/local/src/jdk1.8.0_201/include/linux -I/usr/local/src/jdk1.8.0_201/include -fPIC -c jni_MyJNI.c
     * 5. gcc -shared jni_MyJNI.o -o jni_MyJNI.so
     */
    public static void main(String[] args) {
        int ret = add(5, 6);

        System.out.println("result:" + ret);
    }
}
